<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>附近商家</title>
		<script src="__INDEX__/js/mui.min.js"></script>
		<link href="__INDEX__/css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="__INDEX__/css/style.css" />
		<link rel="stylesheet" href="__INDEX__/css/iconfont.css" />
		<link rel="stylesheet" href="__INDEX__/css/mall.css" />
		<script src="__PUBLIC__/static/js/jquery.min.js"></script>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
		    <h1 class="mui-title">附近商家</h1>
		</header>
		
		<div class="mui-content">
			<div class="shoplist_box">
				<ul class="index_sjlist" id="store_ul">
					
				</ul>
			</div>
		</div>
		<div id="allmap"></div>
		{include file="public/bottom" /}
	</body>

</html>
{include file="public/footer" /}
<script src="__PUBLIC__/static/js/assist.js"></script>
<script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.2&key=eef7f290ac06bdf05b246cebc8cb2fb6&callback=my_getAddress"></script>
<script type="text/javascript">
//获取用户当前地址
var map, geolocation;
function my_getAddress(){
    //加载地图，调用浏览器定位服务
    map = new AMap.Map('container', {
        resizeEnable: true
    });
    map.plugin('AMap.Geolocation', function() {
        geolocation = new AMap.Geolocation({
            enableHighAccuracy: true,//是否使用高精度定位，默认:true
            timeout: 10000,          //超过10秒后停止定位，默认：无穷大
            buttonOffset: new AMap.Pixel(10, 20),//定位按钮与设置的停靠位置的偏移量，默认：Pixel(10, 20)
            zoomToAccuracy: true,      //定位成功后调整地图视野范围使定位位置及精度范围视野内可见，默认：false
            buttonPosition:'RB'
        });
        map.addControl(geolocation);
        geolocation.getCurrentPosition();
        AMap.event.addListener(geolocation, 'complete', onComplete);//返回定位信息
    });
    $('#container').hide();
    //解析定位结果
    function onComplete(data) {
    	$.ajax({
		   	type:"post",
		   	data:{
		   		longitude	: data.position.getLng(),
		   		latitude	: data.position.getLat()
		   	},
		   	url:"{:url('index/index/get_agents')}",
		   	success:function(data){
		   		var html="";
		   		if(data.list){
		   			var list=data.list;
		   			for(var o in list){
		   				var agent=list[o];
		   				var juli = agent.juli;
		   				var diz = agent.address;
		   				var begin_time = ''
		   				var end_time = '';
		   				var dk=0;
		   				if(agent.is_score==1){
		   					dk=agent.ad_score;
		   				}
		   				var action=agent['action'];
		   				if(action==null){
		   					action="暂无";
		   				}
		   				if(juli<1000){
		   					juli = "<1k";
		   				}
		   				if(diz && diz.length>0){
		   					diz = diz.replace('郴州市', '');
		   					diz = diz.replace('湖南省', '');
		   				}else{
		   					diz = '暂无';
		   				}
		   				if(agent.start_time && agent.start_time.length>0){
		   					begin_time = agent.start_time.substr(0,agent.start_time.length-3);
		   				}else{
		   					begin_time = '00:00';
		   				}
		   				if(agent.end_time && agent.end_time.length>0){
		   					end_time = agent.end_time.substr(0,agent.end_time.length-3);;
		   				}else{
		   					end_time = '00:00';
		   				}
		   				var logo=agent.logo;
		   				if(!logo){
		   					logo="__PUBLIC__/static/index/images/noimage.jpg";
		   				}
		   				
		   				var agent_name = agent.agent_name.replace('郴州市', '');
		   				agent_name = agent_name.replace('湖南省', '');
		   				agent_name = agent_name.replace('湖南', '');
		   				if(agent_name.length>12){
		   					agent_name = agent_name.substr(0,12)+".....";
		   				}
						html+="<li>"
							  +"<a href='/index/index/shop_info?agent_id="+agent.id+"' class='clearfix'>"
							  +"<div class='index_sjimg'><img src='"+logo+"'></div>"
							  +"<div class='index_sjinfo'>"
							  +"<div class='index_spname'>"+agent_name+"</div>"
							  +"<div class='index_dkbox clearfix'>"
							  +"<em class='index_dkbl'>鼓励金抵扣</em>"
							  +"<em class='index_dkbr'>"+dk+"%</em>"
							  +"</div>"
							  +"<div class='index_spstyle clearfix'>"
							  +"<span class='index_sjdiz'>"+diz+"</span>"
							  +"<span class='index_sjdw'><i class='iconfont'></i>"+juli+"m</span>"
							  +"</div>"							  
							  +"</div></a>"
							  +"<div class='shopzxhd'><span class='left'>最新活动&nbsp;:&nbsp;</span><span class='right'>"+action+"</span></div>"
							  +"</li>";
					}
		   			$("#store_ul").html(html);
		   		}else{
		   			$("#store_ul").html("<li>附近无商铺<li>");
		   		}
		   	}
   		});
    }
}

	mui.init();
	var aniShow = "pop-in";
	//页面跳转
	mui('#footer-list').on('tap', 'a', function() {
		var id = this.getAttribute('href');
		var href = this.href;
		mui.openWindow({
			id: id,
			url: this.href,
			show: {
				aniShow: aniShow
			},
			waiting: {
				autoShow: false
			}
		});
	});
</script>
